<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>毕业答辩</title>
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all">
    <style>
        .layui-form-item {
            margin-top: 30px;
        }

        .layui-unselect dl dd {
            color: black;
        }
    </style>
</head>
<body class="layui-bg-black">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-md-offset3 layui-bg-black" style="height: 300px;">
            <form class="layui-form" action="" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属题目ID</label>
                    <div class="layui-input-block">
                        <select class="layui-input" id="tid" name="Topic.tid" lay-ignore>
                            <option selected disabled>--------------------------------请选择---------------------------------</option>
                        </select>
                    </div>

                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">题目</label>
                    <div class="layui-input-block">
                        <input type="text" id="item" class="layui-input" lay-verify="required" value=""/>
                    </div>

                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选项A</label>
                    <div class="layui-input-block">
                        <input type="text" name="answerA" id="answerA" class="layui-input" lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选项B</label>
                    <div class="layui-input-block">
                        <input type="text" name="answerB" id="answerB" class="layui-input" lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选项C</label>
                    <div class="layui-input-block">
                        <input type="text" name="answerC" id="answerC" class="layui-input" lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选项D</label>
                    <div class="layui-input-block">
                        <input type="text" name="answerD" id="answerD" class="layui-input" lay-verify="required"/>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="addChose">添加</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<script src="../static/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/layui/layui.js"></script>
<script>
    $(function () {
        $.get('/school_project/topic/selectAllTopic', function (res) {
            console.info(res)
            for (var i = 0; i < res.length; i++) {
                $('#tid').append('<option value="' + res[i].tid + '">' + res[i].tid + '</option>')
            }

        }, 'json')
    })
    $('#tid').change(function () {
        var index = $(this).val();
        console.info(index);
        $.get('/school_project/topic/selectTopicByTid', {'tid': index}, function (res) {
            console.info(res)
            $('#item').val(res.titem);
            $('#item').attr('readonly', 'readonly')
        }, 'json')
    })
    layui.use(['table', 'form', 'layer', 'element'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var element = layui.element;
        //第一个实例
        form.render('select');
        form.on('submit(addChose)', function (data) {
            console.log(data)
            console.info(data.field)
            $.post('/school_project/choose/insertChoose', data.field, function (res) {

                layer.confirm("<span style='color: green'>添加成功</span>", function () {
                    window.location.reload();
                });

            }, 'json');
            return false;
        })
    });
</script>
</body>
</html>
